package com.sw.study.email.service.impl;

import com.sw.study.email.dao.CodeDao;
import com.sw.study.email.service.CodeService;
import com.sw.study.scn.pojo.AuthCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private CodeDao codeDao;

    @Override
    public Boolean codeSave(String email) {
        AuthCode lagouAuthCode = new AuthCode();
        lagouAuthCode.setEmail(email);
        //生成6位随机数字
        Double code = (Math.random()*9+1)*100000;
        System.out.println(code);
        lagouAuthCode.setCode(code.toString());
        Date date=new Date();
        Date date1=new Date(date.getTime()+10*60*1000);
        lagouAuthCode.setCreatetime(date);
        lagouAuthCode.setExpiretime(date1);
        codeDao.save(lagouAuthCode);
        return true;
    }
}
